import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:new_obj/itemPages//settingInfo.dart';
import 'package:new_obj/itemPages/squareInfo.dart';
import 'package:new_obj/itemPages/nearInfo.dart';

class MyApp extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyApp> {
  final items = [
    BottomNavigationBarItem(
        icon: Icon(Icons.home),
        title: new Text("广场", textAlign: TextAlign.center)),
    BottomNavigationBarItem(
        icon: Icon(Icons.near_me),
        title: new Text("附近", textAlign: TextAlign.center)),
    BottomNavigationBarItem(
        icon: Icon(Icons.settings),
        title: new Text("我的", textAlign: TextAlign.center))
  ];
  final bodyList = [squareInfo(), nearInfo(), settingInfo()];
  final pageController = PageController();
  int currentIndex = 0;

  void onTap(int index) {
     pageController.jumpToPage(index);
  }
void onPageChanged(int index)
{
  setState(() {
    currentIndex=index;
  });
}
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
        title: 'Hello World',
        theme: new ThemeData(primarySwatch: Colors.teal),
        home: new Scaffold(
            bottomNavigationBar: BottomNavigationBar(
                items: items, currentIndex: currentIndex, onTap: onTap),
            body:PageView(
              controller: pageController,
                onPageChanged: onPageChanged,
                children:bodyList,
                physics: NeverScrollableScrollPhysics(),
                //
            )
        ));
  }
}

void main() => runApp(MyApp());
